package com.lt73.ext.controller;

import com.lt73.ext.entity.Article;
import com.lt73.ext.entity.User2;
import com.lt73.ext.enums.ActicleStatusEnum;
import com.lt73.ext.repository.User2Repository;
import com.lt73.ext.service.ArticleService;
import com.lt73.ext.service.User2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 关联查询例子
 * @Author: hanxiao
 * @Date: 2022/4/15 11:43
 */
@RestController
@RequestMapping("/user2")
public class User2Controller {

    @Autowired
    private User2Repository repository;

    @Autowired
    private User2Service user2Service;

    @PostMapping("/insert")
    public Boolean insert() {

        //注册用户
        User2 user2 = new User2();
        user2.setIdCardNumber("aaaa");
        user2.setPassword(LocalDateTime.now().toString());
        user2.setUsername("2131");

        return repository.save(user2);
    }

    @PutMapping("/update")
    public Boolean update() {

        //注册用户
        User2 user2 = new User2();
        user2.setId("1514814593479737346");
        user2.setIdCardNumber("bbbb");

        return repository.updateById(user2);
    }

    @GetMapping("/list")
    public List<User2> list() {
        return repository.list();
    }

    @GetMapping("/searchUser2ByName")
    public List<User2> searchUser2ByName(@RequestParam("name") String name) {
        return user2Service.searchUser2ByName(name);
    }
}
